<template>
  <!-- 查看详情 2018/3/7 11:44 zhangQ -->
  <div>
    <Table ref="subOrderRef" :columns="subOrderColumn" :data="subOrderList"></Table>
  </div>
</template>

<script>
  // import {getSubOrderListByGroupId} from '@api/backEnd/station'
  import { dispatchCancelToGroupFleets } from '@api/backEnd/mainOrder'

  export default {
    name: 'view-detail',
    data () {
      let subOrderList = []
      let subOrderColumn = [
        {
          title: '箱号',
          ellipsis: 'false',
          width: 200,
          key: 'containerNo'
        },
        {
          title: '送货地址',
          ellipsis: 'false',
          width: 150,
          key: 'address'
        },
        {
          title: '发货人',
          ellipsis: 'false',
          key: 'shipper',
          width: 250
        },
        {
          title: '收货人',
          ellipsis: 'false',
          key: 'receiver',
          width: 250
        },
        {
          title: '联系人',
          ellipsis: 'false',
          width: 100,
          key: 'outContacts'
        },
        {
          title: '联系人电话',
          ellipsis: 'false',
          width: 150,
          key: 'outMobile'
        },
        {
          title: '品名',
          ellipsis: 'false',
          key: 'pm',
          width: 150
        },
        {
          title: '接取费(元)',
          ellipsis: 'false',
          key: 'receiveFee',
          width: 120
        },
        {
          title: '送达费(元)',
          ellipsis: 'false',
          key: 'deliverFee',
          width: 120
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          fixed: 'right',
          minWidth: 250,
          render: (h, params) => {
            if (this.subOrderList.length > 1) {
              let viewDetailBtn = (<i-button type="primary" size="small" style="margin-right: 5px;" onClick={() => this.dispatchCancelToGroup(params.index, params.row)}>撤销派单</i-button>)
              return (viewDetailBtn)
            }
          }
        }
      ]
      let datas = { subOrderList, subOrderColumn }
      return datas
    },
    props: {
      currentSubOrderList: {
        type: Array,
        default () {
          return []
        }
      }
    },
    computed: {},
    methods: {
      dispatchCancelToGroup (index, row) {
        dispatchCancelToGroupFleets({ subOrderId: row.subOrderId }).then(res => {
          if (+res.data.isSuccess === 1) {
            // this.getData(this.fleets)
            this.subOrderList.splice(index, 1)
            // this.$refs['subOrderRef'].rebuildData.splice(index, 1)
          } else {
            this.$Notice.warning({
              title: '提示',
              desc: '出现错误'
            })
          }
        })
      }
    },
    mounted () {
      let resData = []
      this.currentSubOrderList.forEach((item) => {
        item.state !== 99 && (resData.push(item))
      })
      this.subOrderList = resData
    },
    components: {}
  }
</script>
<style scoped>
  .expand-row {
    margin-bottom: 16px;
  }

  .ivu-table {
    overflow: auto;
  }
</style>
